import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {GlobalConfigsService} from '../global-configs.service';
import {AuthData} from './auth-data';

@Injectable({
  providedIn: 'root'
})
export class AuthService {
  private loginUrl: string;
  private signUpUrl: string;

  constructor(
    private http: HttpClient,
    private globalConfigsService: GlobalConfigsService,
  ) {
    this.loginUrl = this.globalConfigsService.getLoginUrl();
    this.signUpUrl = this.globalConfigsService.getSingUpUrl();
  }

  login(mobileNumber: number, password: string, captchaResponse: string): void {
    const authData: AuthData = {mobileNumber, password, captchaResponse};
    this.http.post(this.loginUrl, {mobileNumber, password, captchaResponse}).subscribe(_ => console.log(_));
  }

  signUp(form: { mobileNumber: number, nationalId: number, password: string }) {
    this.http.post(this.signUpUrl, form).subscribe(_ => console.log('success', _));
  }
}
